cmake_minimum_required(VERSION 2.6)
cmake_policy(SET CMP0001 NEW) # don't use MAKE_BACKWARDS_COMPATIBILITY but policies instead

project(chipmunk)

SET(PROJECT_NAME chipmunk)
SET(PROJECT_VERSION 5.3.1)

# to change the prefix, run cmake with the parameter:
#   -D CMAKE_INSTALL_PREFIX=/my/prefix

# to change the build type, run cmake with the parameter:
#   -D CMAKE_BUILD_TYPE=<build-type>
# run "cmake --help-variable CMAKE_BUILD_TYPE" for details
set(CMAKE_BUILD_TYPE Release)

# other options for the build, you can i.e. activate the ruby bindings by passing
#   -D BUILD_RUBY_EXT=ON
# to cmake. Other options analog
option(BUILD_DEMOS "Build the demo applications" OFF)
option(INSTALL_DEMOS "Install the demo applications" OFF)
option(BUILD_SHARED "Build and install the shared library" ON)
option(BUILD_STATIC "Build as static library" ON)
option(INSTALL_STATIC "Install the static library" ON)
option(BUILD_RUBY_EXT "Build and install the Ruby extension" OFF)

set (prefix ${CMAKE_INSTALL_PREFIX})
set (exec_prefix "${prefix}")
set (libdir "${exec_prefix}/lib")
set (includedir "${prefix}/include")
configure_file("${PROJECT_SOURCE_DIR}/chipmunk.pc.in" "${PROJECT_BINARY_DIR}/chipmunk.pc")

# sanity checks...
if(INSTALL_DEMOS)
  set(BUILD_DEMOS ON FORCE)
endif(INSTALL_DEMOS)
# thse need the static lib too
if(BUILD_DEMOS OR BUILD_RUBY_EXT OR INSTALL_STATIC)
  set(BUILD_STATIC ON FORCE)
endif(BUILD_DEMOS OR BUILD_RUBY_EXT OR INSTALL_STATIC)

IF (WIN32)
    #    # compile as C++
    #set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /TP")
    #set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} /TP") 
    #set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /TP")
    ADD_DEFINITIONS(" /TP ")
ELSE ()
    set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99") # allways use gnu99
    set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE} -ffast-math") # extend release-profile with fast-math
    set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -Wall") # extend debug-profile with -Wall
ENDIF (WIN32)

add_subdirectory(src)

if(BUILD_DEMOS)
  add_subdirectory(Demo)
endif(BUILD_DEMOS)

if(BUILD_RUBY_EXT)
  add_subdirectory(ruby)
endif(BUILD_RUBY_EXT)

#pkgconfig
install (FILES "${PROJECT_BINARY_DIR}/chipmunk.pc" DESTINATION lib/pkgconfig)

# Packing stuff
SET(CPACK_PACKAGE_VENDOR "FMSoft")
SET(CPACK_PACKAGE_NAME "${PROJECT_NAME}")
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "a simple, lightweight, fast and portable 2D rigid body physics library written in C")
SET(CPACK_SOURCE_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${PROJECT_VERSION}")
SET(CPACK_SOURCE_GENERATOR "TGZ")
SET(CPACK_SOURCE_IGNORE_FILES
      "/auto/;/cmake/;/.svn/;/.git/;/.bzr/;/CMakeFiles/;/_CPack_Packages/;CMakeCache.txt$;
      ~$;.swp$;.cmake$;
      ${CPACK_SOURCE_IGNORE_FILES}")

INCLUDE(CPack)

